package com.example.p42;

import java.io.File;
import java.io.IOException;

/**
 * @author Lenovo
 */
public class RunoobTest {
    public static void main(String[] args) throws IOException {
        File oldName = new File("C:/myjavafile.txt");
        File newName = new File("C:/myjavafile2.txt");
        if (newName.exists()){
            throw new IOException("文件已存在");
        }
        if (oldName.renameTo(newName)){
            System.out.println("文件重命名成功");
        }else{
            System.out.println("文件重命名失败");
        }

    }
}
